package com.xoa.controller.party;

import com.xoa.model.party.OrgPartyMember;
import com.xoa.service.party.OrgPartyMemberService;
import com.xoa.util.ToJson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.beans.Transient;
import java.text.SimpleDateFormat;

@Controller
@RequestMapping("/OrgPartyMember")
public class OrgPartyMemberController {
    @Resource
    private OrgPartyMemberService orgPartyMemberService;

    @Transient
    @ResponseBody
    @RequestMapping("/insert")
    public ToJson insert(OrgPartyMember orgPartyMember, String admissionDate1, String becomeDate1, HttpServletRequest request){
         try{
             SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
             if(becomeDate1!=null && !(becomeDate1.equals(""))){
                 orgPartyMember.setBecomeDate(format.parse(becomeDate1));
             }
             if(admissionDate1!=null && !(admissionDate1.equals(""))){
                 orgPartyMember.setAdmissionDate(format.parse(admissionDate1));
             }
         }catch (Exception e){
             e.printStackTrace();
         }
         return orgPartyMemberService.insert(orgPartyMember,request);
    }

    @Transient
    @ResponseBody
    @RequestMapping("/update")
    public ToJson update(OrgPartyMember orgPartyMember, String admissionDate1, String becomeDate1){
        try{
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            if(becomeDate1!=null && !(becomeDate1.equals(""))){
                orgPartyMember.setBecomeDate(format.parse(becomeDate1));
            }
            if(admissionDate1!=null && !(admissionDate1.equals(""))){
                orgPartyMember.setAdmissionDate(format.parse(admissionDate1));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return orgPartyMemberService.update(orgPartyMember);
    }

    @Transient
    @ResponseBody
    @RequestMapping("/delete")
    public ToJson delete(String opIds){
        return orgPartyMemberService.delete(opIds);
    }

    @ResponseBody
    @RequestMapping("/selectList")
    public ToJson selectList(OrgPartyMember orgPartyMember, Integer page, Integer pageSize, Boolean userFlag){
        return orgPartyMemberService.select(orgPartyMember,page,pageSize,userFlag);
    }
    @ResponseBody
    @RequestMapping("/selectOrgDeptandChDept")
    public ToJson selectOrgDeptandChDept(Integer orgDeptId){
        return orgPartyMemberService.selectOrgDeptandChDept(orgDeptId);
    }
    @ResponseBody
    @RequestMapping("/selectByList")
    public ToJson selectByList(OrgPartyMember orgPartyMember, Integer page, Integer pageSize, Boolean userFlag){//后边在补充条件，累了
        return orgPartyMemberService.selectByList(orgPartyMember,page,pageSize,userFlag);
    }

    @RequestMapping("/ecoudInsert")
    @ResponseBody
    @Transient
    public ToJson ecoudInsert(MultipartFile file){
        return orgPartyMemberService.ecoudInsert(file);
    }

    @RequestMapping("/selectByUserId")
    @ResponseBody
    public ToJson selectByUserId(String UserId){
        return orgPartyMemberService.selectByUserId(UserId);
    }
}
